layui.define(['form','table', 'laydate'], function(exports){
  var $ = layui.$,form = layui.form,table = layui.table, laydate = layui.laydate;

    laydate.render({
        elem: '#searchDate'
        , range: true
    });

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/bxscn/order/list.data'
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
      {field: 'tradeNo', title: '订单号'}
      ,{field: 'leaseDeviceSn', title: '租借设备',templet:function (record){
          if(record.leaseDeviceSn) {
              return record.leaseDeviceSn + '(卡槽：' + record.leaseSlotNum + ')';
          }else{
              return '--';
          }
      }}
      ,{field: 'revertDeviceSn', title: '归还设备',templet:function (record){
          if(record.revertDeviceSn) {
              return record.revertDeviceSn + '(卡槽：' + record.revertSlotNum + ')';
          }else{
              return '--';
          }
      }}
      ,{field: 'portableBatterySn', title: '电池ID'}
      ,{field: 'useDurationStr', title: '使用时长'}
      ,{field: 'moneyStr', title: '订单金额'}
      ,{field: 'depositMoneyStr', title: '押金'}
      ,{field: 'payStateName', title: '支付状态'}
      ,{field: 'stateName', title: '状态'}
      ,{field: 'createDate', title: '创建时间'}
      ,{title: '操作', width: 80, align:'center', fixed: 'right', toolbar: '#LAY-table-toolbar'}
    ]]
    ,page: true
    ,limit: 30
    ,height: 'full-220'
    ,text: '对不起，加载出现异常！'
  });
  
  //监听搜索
  form.on('submit(LAY-search)', function(data){
    var field = data.field;
    //执行重载
    table.reload('LAY-table', {
      where: field
      ,page: {curr: 1}
    });
  });
  
  //事件
  var active = {
    info:function(obj){
    	layer.open({
            type: 2
            ,title: '便携式电池租借订单详情'
            ,content: layui.setter.webRoot + '/bxscn/order/info.html?tradeNo='+obj.data.tradeNo+'&createDate='+obj.data.createDate
            ,maxmin: true
            ,area: ['80%', '80%']
        });
    }
  };
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('bxscn_order_list', {})
});